package com.moon.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {
    private static ObjectMapper objectMapper = new ObjectMapper();

    //序列化
    public static String toJson(Object obj) {
        try {
            return objectMapper.writeValueAsString(obj);
        } catch (Exception e) {
            //e.printStackTrace();
            return null;
        }
    }

    //反序列化
    public static <T> T toObj(String content, Class<T> clazz) {
        try {
            return objectMapper.readValue(content, clazz);
        } catch (Exception e) {
            //e.printStackTrace();
            return null;
        }
    }

    //
}
